<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            在这里输入学生学号，直接将学生导入班级
        </blockquote>
        <form class="layui-form" action="">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>学号</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">学号</label>
                <div class="layui-input-block layui-inline" style="width: 20%;margin-left: unset">
                    <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入学号"
                           class="layui-input">
                </div>
            </div>
            <center>
                <button class="layui-btn" lay-submit="" lay-filter="demo2" style="margin: 0 auto">保存</button>
            </center>
        </form>

    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：待定 ', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
</script>